package stdlib.net

import java.io.File
import java.net.URL



fun testURL(){
    val url = URL("http://localhost:8000/file")
    println(url)
    println(url.file)
}

fun testURL2(){
    val url = URL("http://localhost:8000/zip")
    println("开始下载...")
    val connection = url.openConnection()
    println("接口信息...")
    println(connection.contentLength)
    println(connection.contentType)
    println(connection.contentEncoding)
    println("开始下载...")
    File("1.zip").writeBytes(connection.getInputStream().readBytes())
    println("下载结束...")
}

fun testURL3(){
    val url = URL("http://localhost:8000/zip")
    println("开始下载...")
    val openStream = url.openStream()
    println("接口信息...")
    println("开始下载...")
    File("1.zip").writeBytes(openStream.readBytes())
    println("下载结束...")
}


fun main(){
    testURL()
    testURL2()
}